package com.jkoss.biz.imp.kc;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.jkoss.biz.kc.couBiz;
import com.jkoss.dao.kc.CourseMapper;
import com.jkoss.pojo.kc.Course;
import com.jkoss.pojo.kc.CourseExample;
import com.jkoss.tool.Page;

@Component
public class couBizImpl  implements couBiz{
   
	@Autowired
	private CourseMapper couDao;
	
	
	@Override
	public List<Course> listCou(Page<Course> page) {
		
		return couDao.listCou(page);
	}

	@Override
	public Course findById(Integer kcid) {
		       
		return couDao.selectByPrimaryKey(kcid);
	}

	@Override
	@Transactional
	public String delCou(Integer kcid) {
		return couDao.deleteByPrimaryKey(kcid)>0?"删除成功":"删除失败";
	}

	@Override
	@Transactional
	public String addCou(Course course) {
		
		return couDao.insert(course)>0?"添加成功":"添加失败";
	}

	@Override
	@Transactional
	public String upCou(Course c) {
		
		return couDao.updateByPrimaryKey(c)>0?"修改成功":"修改失败";
	}

	@Override
	public List<Course> listByCou() {
		
		return couDao.listByCou();
	}

 
	public Course findByName(String kcname) {
		
		CourseExample courseExample=new CourseExample();
		
		com.jkoss.pojo.kc.CourseExample.Criteria criteria=courseExample.createCriteria();
		
		criteria.andKcnameEqualTo(kcname);
		List<Course> co=couDao.selectByExample(courseExample);
		if(co.size()>0){
		return co.get(0);
		}
		return null;
	}

}
